import requests,os

class api_base():
    def __init__(self,url="http://10.59.9.18/"):
        self.url = url
        self.session = requests.Session()
        self.timeout = 10
        self.headers = {}

    def get_full_url(self,path):
        return f'{self.url}{path}' # 只返回字符串，不发请求

    # post
    def post(self,path="",**kwargs):
        full_url = self.get_full_url(path)
        if 'timeout' not in kwargs:
            kwargs['timeout'] = self.timeout
        return self.session.post(url=full_url,**kwargs)
    # get
    def get(self,path="",**kwargs):
        full_url = self.get_full_url(path)
        if 'timeout' not in kwargs:
            kwargs['timeout'] = self.timeout
        return self.session.get(url=full_url,**kwargs)
    # put
    def put(self,path="",**kwargs):
        full_url = self.get_full_url(path)
        if 'timeout' not in kwargs:
            kwargs['timeout'] = self.timeout
        return self.session.put(url=full_url,**kwargs)
    # delete
    def delete(self,path="",**kwargs):
        full_url = self.get_full_url(path)
        if 'timeout' not in kwargs:
            kwargs['timeout'] = self.timeout
        return self.session.delete(url=full_url,**kwargs)

    def close(self):
        """关闭 session，释放资源"""
        self.session.close()









